#include<pthread.h>
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>

void* pthread_fun(void *arg)
{
    int i = 0;
    while(1)
    {
        if(i == 3)
        {
            //子线程运行3秒后，退出
            static char *str = "退出子线程\n";
            pthread_exit((void*)str);
        }
        printf("子线程执行%ds\n",++i);
        sleep(1);
    }
}
int main()
{
    printf("进程执行中...\n");
    pthread_t id;
    if(pthread_create(&id,NULL,pthread_fun,NULL) == -1)
    {
        perror("fail to pthread");
        exit(-1);
    }
    //调用pthread_join释放线程资源，并接收线程返回状态
    char *buf;
    pthread_join(id,(void**)&buf);
    printf("%s",buf);
    printf("进程退出\n");
    return 0;
}